package org.iartisan.admin.template.config.shiro;


import org.apache.shiro.web.filter.authc.UserFilter;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

/**
 * ajax 超时后处理和判断
 */
public class AjaxTimeoutAccessFilter extends UserFilter {

    @Override
    protected boolean onAccessDenied(ServletRequest servletRequest, ServletResponse servletResponse) throws Exception {
        //判断请求是否是ajax 请求
        if ("XMLHttpRequest".equalsIgnoreCase(((HttpServletRequest) servletRequest).getHeader("X-Requested-With"))) {
            servletResponse.getWriter().print("timeout");
        } else {
            this.saveRequestAndRedirectToLogin(servletRequest, servletResponse);
        }
        return false;
    }
}
